
*********************************************************************************
** PRELIMINARIES
*********************************************************************************

********************************************************************
** WAVE 1 POST-HARVEST DATA
********************************************************************

** Roster Information
use "$dir/rawdata/LSMS Nigeria/2012/Post Harvest Wave 2/Household/sect1_harvestw2.dta", clear // ROSTER

count
local samplesize=`r(N)'
merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2012/Post Harvest Wave 2/Household/sect2a_harvestw2.dta", gen(merge_sec2a) assert(master matched) // EDUCATION, A
merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2012/Post Harvest Wave 2/Household/sect2b_harvestw2.dta", gen(merge_sec2b) assert(master matched) // EDUCATION, B
merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2012/Post Harvest Wave 2/Household/sect3a_harvestw2.dta", gen(merge_sec3a) assert(master matched) // LABOR, A
merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2012/Post Harvest Wave 2/Household/sect3b_harvestw2.dta", gen(merge_sec3b) assert(master matched) // LABOR, B
merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2012/Post Harvest Wave 2/Household/sect4a_harvestw2.dta", gen(merge_sec4a) assert(master matched) // HEALTH

** Still in HH
gen w2h_inhh=s1q14!=2

** Household size
gen temp=1 if w2h_inhh==1
bys hhid: egen w2h_hh_size=total(temp)
drop temp

** Number of children 12 or younger
gen temp=1 if s1q4<=12 & w2h_inhh==1
bys hhid: egen w2h_hh_under12=total(temp)
drop temp

** Number of youth 18 or younger
gen temp=1 if s1q4<=18 & w2h_inhh==1
bys hhid: egen w2h_hh_under18=total(temp)
drop temp

** Number of adults 60 or older
gen temp=1 if s1q4>=60 & !missing(s1q4) & s1q4!=999 & w2h_inhh==1
bys hhid: egen w2h_hh_over60=total(temp)
drop temp

** Adults 12 to 60
gen temp=1 if s1q4>12 & s1q4<60 & !missing(s1q4) & s1q4!=999 & w2h_inhh==1
bys hhid: egen w2h_hh_12to60=total(temp)
drop temp

** Marital status
gen w2h_married=(s1q7==1 | s1q7==2) if !missing(s1q7)
gen w2h_married_monog=s1q7==1 if !missing(s1q7)
gen w2h_married_polyg=s1q7==2 if !missing(s1q7)

** Female
gen w2h_female=(s1q2==2) if !missing(s1q2)

** Age
gen w2h_age=s1q4
replace w2h_age=. if w2h_age==999

** Age of spouse
sum indiv 
forvalues x=1/`r(max)' {
	gen age_person`x'_temp=s1q4 if indiv==`x' & !missing(s1q4)
	bys hhid: egen age_person`x'=max(age_person`x'_temp)
	drop age_person`x'_temp
}

** Average age of others in the household
sum indiv 
forvalues x=1/`r(max)' {
	replace age_person`x'=. if indiv==`x'
}
egen w2h_hh_avgage=rowmean(age_person*)

** Spouse age
sum indiv
forvalues x=1/`r(max)' {
	replace age_person`x'=. if s1q12!=`x'
}
egen w2h_spouse_age=rowmean(age_person*)

** Age gap
gen w2h_spouse_agegap=w2h_age-w2h_spouse_age

** Birthday
gen w2h_birthday=mdy(s1q6_month,s1q6_day,s1q6_year)
format w2h_birthday %td

** Birth year
gen w2h_birthyear=s1q6_year
recode w2h_birthyear 9999=. 9998=.
replace w2h_birthyear=2013-w2h_age if missing(w2h_birthyear)

** Highest education of individual
gen w2h_educ=s2aq9
replace w2h_educ=0 if s2aq6==2 // Never attended school
label values w2h_educ S2AQ9
replace w2h_educ=. if s2aq9==98

** Still in school
gen w2h_inschool=(s2aq13==1) if !missing(s2aq13)

** Literate
gen w2h_literate=(s2aq5==1) if !missing(s2aq5)

** Worked for a non-HH member
gen w2h_work_outsideHH=s3aq1==1 if !missing(s3aq1)

** Worked in agriculture for a HH member
gen w2h_work_agHH=s3aq2==1 if !missing(s3aq2)

** Worked in HH business
gen w2h_work_bizHH=s3aq3==1 if !missing(s3aq3)

** Any work in last 7 days (agriculture, for non-HH member, own account/business)
gen w2h_worked_last7days=0
replace w2h_worked_last7days=1 if s3aq1==1
replace w2h_worked_last7days=1 if s3aq2==1 
replace w2h_worked_last7days=1 if s3aq3==1
replace w2h_worked_last7days=. if missing(s3aq1) & missing(s3aq2) & missing(s3aq3)

** Hours worked in last 7 days
egen w2h_work_hrs=rowtotal(s3aq15 s3aq27)
replace w2h_work_hrs=. if missing(w2h_worked_last7days)

** Works in agriculture
gen w2h_work_agri=(w2h_work_agHH==1 | s3aq11==1) if (!missing(w2h_work_agHH) | !missing(s3aq23))

** Industry of occupation
gen w2h_occ=s3aq11
label values w2h_occ S3AQ11

** Highest education of biological father
gen w2h_father_educ=s1q21
label values w2h_father_educ S1Q21
replace w2h_father_educ=. if w2h_father_educ==98

** Industry of occupation of biological father
gen w2h_father_occ=s1q22
label values w2h_father_occ S1Q22

** Highest education of biological mother
gen w2h_mother_educ=s1q26
label values w2h_mother_educ S1Q26
replace w2h_mother_educ=. if w2h_mother_educ==98

** Industry of occupation of biological mother
gen w2h_mother_occ=s1q27
label values w2h_mother_occ S1Q27

** ID of father and mother (for linking)
gen w2h_father_id=s1q19 
gen w2h_mother_id=s1q24

** GEOGRAPHIC INFORMATION
gen w2h_geo_urban=(sector==1) if !missing(sector)
gen w2h_geo_state=state
gen w2h_geo_lga=lga
replace w2h_geo_lga=s1q31b if !missing(s1q31b) // LGA code for where the HH member moved
label var w2h_geo_urban "Urban residence"
label var w2h_geo_state "State of residence"
label var w2h_geo_lga "LGA of residence" 

** DISABILITIES

	** Difficulty seeing
		tab1 s4aq23, nol
		tab1 s4aq23
		gen w2h_diff_seei=1 if inlist(s4aq23, 2, 3, 4) 
		replace w2h_diff_seei=0 if inlist(s4aq23, 1)
		replace w2h_diff_seei=. if inlist(s4aq23, .)
		tab1 w2h_diff_seei

	** Difficulty hearing
		tab1 s4aq25, nol
		tab1 s4aq25
		gen w2h_diff_hear=1 if inlist(s4aq25, 2, 3, 4) 
		replace w2h_diff_hear=0 if inlist(s4aq25, 1)
		replace w2h_diff_hear=. if inlist(s4aq25, .)
		tab1 w2h_diff_hear

	** Difficulty walking or climbing stairs	
		tab1 s4aq27, nol
		tab1 s4aq27
		gen w2h_diff_walk_clim=1 if inlist(s4aq27, 2, 3, 4) 
		replace w2h_diff_walk_clim=0 if inlist(s4aq27, 1)
		replace w2h_diff_walk_clim=. if inlist(s4aq27, .)
		tab1 w2h_diff_walk_clim

	** Difficulty remembering or concentrating
		tab1 s4aq29, nol
		tab1 s4aq29
		gen w2h_diff_reme=1 if inlist(s4aq29, 2, 3, 4) 
		replace w2h_diff_reme=0 if inlist(s4aq29,1)
		replace w2h_diff_reme=. if inlist(s4aq29, .)
		tab1 w2h_diff_reme

	** Difficulty with self-care
		tab1 s4aq31, nol
		tab1 s4aq31
		gen w2h_diff_self_care=1 if inlist(s4aq31, 2, 3, 4)
		replace w2h_diff_self_care=0 if inlist(s4aq31, 1)
		replace w2h_diff_self_care=. if inlist(s4aq31, .)
		tab1 w2h_diff_self_care

	** Difficulty communicating
		tab1 s4aq33, nol
		tab1 s4aq33
		gen w2h_diff_comm=1 if inlist(s4aq33, 2, 3, 4) 
		replace w2h_diff_comm=0 if inlist(s4aq33, 1)
		replace w2h_diff_comm=. if inlist(s4aq33, .)
		tab1 w2h_diff_comm
		
********************************************************************
********************************************************************

** HEALTH

	** Any illness or injury during the last 4 weeks
		gen w2h_ill_inj=(s4aq3==1 | s4aq3==2) if !missing(s4aq3)
	
	** Had to stop usual activity in the past 4 weeks
		gen w2h_ill_inj_stopactivity=(s4aq4==1) if !missing(s4aq4)
		replace w2h_ill_inj_stopactivity=0 if w2h_ill_inj==0
		
** HH Size

	merge m:1 hhid using "$dir/rawdata/LSMS Nigeria/2012/cons_agg_wave2_visit2.dta", assert(master matched) nogen

	gen w2h_urban_fromcons=(rururb==1) if !missing(rururb)
	order w2h_urban_fromcons, after(rururb)
	label var w2h_urban_fromcons "Urban residence"

	ren hhsize w2h_hhsize_fromcons
	ren totcons w2h_conspc
	
** Save

	keep hhid indiv w2*
	order hhid indiv w2h_geo*
	save "$dir/data/NGA_w2h_individual.dta", replace
